home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Taiji Applet Pack v2.7 / DateText / DateText.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-11-06  |  9.5 KB  |  426 lines

  1. import java.applet.Applet;
  2. import java.applet.AudioClip;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Cursor;
  6. import java.awt.Font;
  7. import java.awt.FontMetrics;
  8. import java.awt.Graphics;
  9. import java.awt.Image;
  10. import java.awt.MediaTracker;
  11. import java.awt.event.MouseEvent;
  12. import java.awt.event.MouseListener;
  13. import java.net.MalformedURLException;
  14. import java.net.URL;
  15. import java.net.URLEncoder;
  16. import java.text.DateFormat;
  17. import java.util.Calendar;
  18.  
  19. public class DateText extends Applet implements Runnable, MouseListener {
  20.    private Thread thread;
  21.    // $FF: renamed from: b java.awt.Graphics
  22.    private Graphics field_0;
  23.    private Image buffer;
  24.    private Image backImage;
  25.    private boolean loaded = false;
  26.    private boolean isBackImage = false;
  27.    private boolean paintable = false;
  28.    private boolean move = true;
  29.    private boolean firstime = true;
  30.    // $FF: renamed from: wi int
  31.    private int field_1;
  32.    // $FF: renamed from: he int
  33.    private int field_2;
  34.    private int decy;
  35.    private int decx;
  36.    private int text_height;
  37.    private int string_width;
  38.    private Color textColor;
  39.    private String backImageName;
  40.    private String text;
  41.    private Color backColor;
  42.    // $FF: renamed from: df java.text.DateFormat
  43.    private DateFormat field_3;
  44.    // $FF: renamed from: fm java.awt.FontMetrics
  45.    private FontMetrics field_4;
  46.    private Color enterBackColor;
  47.    private Color enterTextColor;
  48.    private AudioClip sound;
  49.    private AudioClip clicSound;
  50.    private AudioClip enterSound;
  51.    private boolean loopSound;
  52.    private String link;
  53.    private String statusBarText;
  54.    private int wiBack;
  55.    private int heBack;
  56.  
  57.    public String getAppletInfo() {
  58.       return "Name: DateText\r\nAuthor: Taiji Software\r\n";
  59.    }
  60.  
  61.    public DateText() {
  62.       this.textColor = Color.black;
  63.       this.text_height = 10;
  64.       this.decx = 0;
  65.       this.decy = 0;
  66.       ((Component)this).addMouseListener(this);
  67.    }
  68.  
  69.    public void register() {
  70.       try {
  71.          URL u = new URL("http://www.taijisoftware.com");
  72.          ((Applet)this).getAppletContext().showDocument(u, "_blank");
  73.          this.stop();
  74.       } catch (Exception e) {
  75.          System.out.println(e);
  76.          this.stop();
  77.       }
  78.    }
  79.  
  80.    public void init() {
  81.       String codeBase = null;
  82.  
  83.       try {
  84.          codeBase = (new URL(((Applet)this).getCodeBase().toString())).getHost();
  85.          System.out.println("Copyright 1999, 2001 Taiji Software(tm)\nYour domain name is : " + codeBase);
  86.          codeBase = codeBase.toUpperCase();
  87.       } catch (Exception var9) {
  88.       }
  89.  
  90.       if (!((Applet)this).getCodeBase().toString().toUpperCase().startsWith("FILE") || ((Applet)this).getParameter("debug") != null) {
  91.          String regCode = ((Applet)this).getParameter("registration_code");
  92.          if (regCode == null) {
  93.             regCode = ((Applet)this).getParameter("reg_domain");
  94.             if (regCode == null) {
  95.                this.register();
  96.             } else {
  97.                if (regCode.length() == codeBase.length() + 4 && !codeBase.startsWith("WWW.")) {
  98.                   codeBase = "WWW." + codeBase;
  99.                } else if (regCode.length() == codeBase.length() - 4 && codeBase.startsWith("WWW.")) {
  100.                   codeBase = codeBase.substring(4);
  101.                }
  102.  
  103.                char[] chars = new char[codeBase.length()];
  104.                codeBase.getChars(0, codeBase.length(), chars, 0);
  105.                String key = new String("haricot");
  106.                char[] chars2 = new char[key.length()];
  107.                key.getChars(0, key.length(), chars2, 0);
  108.  
  109.                for(int i = 0; i < codeBase.length(); ++i) {
  110.                   int j;
  111.                   if (i >= key.length()) {
  112.                      j = i - key.length() * (i / key.length());
  113.                   } else {
  114.                      j = i;
  115.                   }
  116.  
  117.                   chars[i] += chars2[j];
  118.                   chars[i] = (char)(chars[i] - chars[i] / 26 * 26 + 97);
  119.                }
  120.  
  121.                String res = new String(chars);
  122.                if (!res.equalsIgnoreCase(regCode)) {
  123.                   this.register();
  124.                }
  125.             }
  126.          } else if (!regCode.equals("settevercsedegnamiaj") && !regCode.equals("8078")) {
  127.             this.register();
  128.          }
  129.       }
  130.  
  131.       this.getParameters();
  132.       this.move = true;
  133.       if (this.sound != null) {
  134.          if (this.loopSound) {
  135.             this.sound.loop();
  136.             return;
  137.          }
  138.  
  139.          this.sound.play();
  140.       }
  141.  
  142.    }
  143.  
  144.    public void getParameters() {
  145.       this.field_1 = ((Component)this).getSize().width;
  146.       this.field_2 = ((Component)this).getSize().height;
  147.       this.textColor = this.getColor("text_color");
  148.       this.backColor = this.getColor("background_color");
  149.       ((Component)this).setBackground(this.backColor);
  150.       this.enterBackColor = this.getColor("enter_background_color");
  151.       this.enterTextColor = this.getColor("enter_text_color");
  152.       String s = ((Applet)this).getParameter("text_height");
  153.       if (s != null) {
  154.          this.text_height = Integer.parseInt(s);
  155.       }
  156.  
  157.       s = ((Applet)this).getParameter("height_shift");
  158.       if (s != null) {
  159.          this.decy = Integer.parseInt(s);
  160.       }
  161.  
  162.       s = ((Applet)this).getParameter("width_shift");
  163.       if (s != null) {
  164.          this.decx = Integer.parseInt(s);
  165.       }
  166.  
  167.       this.backImageName = ((Applet)this).getParameter("background_image");
  168.       if (this.backImageName != null) {
  169.          this.isBackImage = true;
  170.       }
  171.  
  172.       this.statusBarText = ((Applet)this).getParameter("status_bar_text");
  173.       s = ((Applet)this).getParameter("sound_name");
  174.       if (s != null) {
  175.          this.sound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  176.       }
  177.  
  178.       s = ((Applet)this).getParameter("loop_sound");
  179.       if (s != null) {
  180.          if (s.equals("yes")) {
  181.             this.loopSound = true;
  182.          } else {
  183.             this.loopSound = false;
  184.          }
  185.       }
  186.  
  187.       s = ((Applet)this).getParameter("clic_sound_name");
  188.       if (s != null) {
  189.          this.clicSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  190.       }
  191.  
  192.       s = ((Applet)this).getParameter("enter_sound_name");
  193.       if (s != null) {
  194.          this.enterSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  195.       }
  196.  
  197.       this.link = ((Applet)this).getParameter("link");
  198.    }
  199.  
  200.    public Color getColor(String param) {
  201.       String s = ((Applet)this).getParameter(param);
  202.       if (s != null) {
  203.          if (s.substring(0, 1).equals("#")) {
  204.             s = s.substring(1);
  205.             int i = Integer.parseInt(s, 16);
  206.             return new Color(i);
  207.          } else {
  208.             return null;
  209.          }
  210.       } else {
  211.          return null;
  212.       }
  213.    }
  214.  
  215.    public final void paint(Graphics g) {
  216.       if (this.paintable) {
  217.          this.field_0.clearRect(0, 0, this.field_1, this.field_2);
  218.          if (this.isBackImage & this.loaded) {
  219.             this.field_0.drawImage(this.backImage, (this.field_1 - this.wiBack) / 2, (this.field_2 - this.heBack) / 2, this);
  220.          }
  221.  
  222.          this.field_0.drawString(this.text, this.decx, this.text_height + this.decy);
  223.          g.drawImage(this.buffer, 0, 0, this);
  224.       }
  225.  
  226.    }
  227.  
  228.    public final void update(Graphics g) {
  229.       this.paint(g);
  230.    }
  231.  
  232.    public void start() {
  233.       this.move = true;
  234.       if (this.thread == null) {
  235.          this.thread = new Thread(this);
  236.          this.thread.start();
  237.       }
  238.  
  239.    }
  240.  
  241.    public void stop() {
  242.       if (this.thread != null) {
  243.          this.move = false;
  244.          this.thread = null;
  245.       }
  246.  
  247.       if (this.sound != null) {
  248.          this.sound.stop();
  249.       }
  250.  
  251.    }
  252.  
  253.    public final void run() {
  254.       if (this.firstime) {
  255.          if (this.isBackImage) {
  256.             MediaTracker tracker = new MediaTracker(this);
  257.             this.backImage = ((Applet)this).getImage(((Applet)this).getCodeBase(), this.backImageName);
  258.             tracker.addImage(this.backImage, 0);
  259.  
  260.             try {
  261.                tracker.waitForAll();
  262.                this.loaded = !tracker.isErrorAny();
  263.             } catch (InterruptedException var6) {
  264.                this.stop();
  265.             }
  266.  
  267.             if (!this.loaded) {
  268.                this.stop();
  269.                return;
  270.             }
  271.          }
  272.  
  273.          this.buffer = ((Component)this).createImage(this.field_1, this.field_2);
  274.          this.field_0 = this.buffer.getGraphics();
  275.          String fontName = ((Applet)this).getParameter("text_font");
  276.          if (fontName == null) {
  277.             fontName = "TimesRoman";
  278.          }
  279.  
  280.          int style = 1;
  281.          String s = ((Applet)this).getParameter("text_style");
  282.          if (s != null) {
  283.             if (s.equals("bold")) {
  284.                style = 1;
  285.             } else if (s.equals("italic")) {
  286.                style = 2;
  287.             } else if (s.equals("bold_italic")) {
  288.                style = 3;
  289.             } else {
  290.                style = 0;
  291.             }
  292.          }
  293.  
  294.          this.field_0.setFont(new Font(fontName, style, this.text_height));
  295.          DateFormat df = DateFormat.getDateTimeInstance(2, 2);
  296.          this.text = df.format(Calendar.getInstance().getTime());
  297.          this.field_4 = this.field_0.getFontMetrics();
  298.          this.string_width = this.field_4.stringWidth(this.text);
  299.          if (this.isBackImage) {
  300.             this.wiBack = this.backImage.getWidth(this);
  301.             this.heBack = this.backImage.getHeight(this);
  302.          }
  303.  
  304.          if (this.decx == 0) {
  305.             this.decx = (this.field_1 - this.string_width) / 2;
  306.          }
  307.  
  308.          if (this.decy == 0) {
  309.             this.decy = (this.field_2 + this.field_4.getMaxAscent() - this.field_4.getMaxDescent()) / 2 - this.text_height;
  310.          }
  311.  
  312.          this.field_0.setColor(this.textColor);
  313.          this.paintable = true;
  314.          this.firstime = false;
  315.       }
  316.  
  317.       while(this.move) {
  318.          this.field_3 = DateFormat.getDateTimeInstance(2, 2);
  319.          this.text = this.field_3.format(Calendar.getInstance().getTime());
  320.          ((Component)this).repaint();
  321.  
  322.          try {
  323.             Thread.sleep(100L);
  324.          } catch (InterruptedException e) {
  325.             System.err.println(e);
  326.             this.stop();
  327.          }
  328.       }
  329.  
  330.    }
  331.  
  332.    public URL giveURL(String url) {
  333.       try {
  334.          if (url.toUpperCase().startsWith("HTTP")) {
  335.             return new URL(url);
  336.          } else if (url.toUpperCase().startsWith("FTP")) {
  337.             int p = url.indexOf(":");
  338.             int p2 = url.indexOf(":", p + 1);
  339.             if (p2 != -1) {
  340.                url = url.substring(0, p + 3) + URLEncoder.encode(url.substring(p + 3, url.length()));
  341.             }
  342.  
  343.             p = url.indexOf("%40");
  344.             if (p != -1) {
  345.                url = url.substring(0, p) + "@" + url.substring(p + 3, url.length());
  346.             }
  347.  
  348.             return new URL(url);
  349.          } else {
  350.             return new URL(((Applet)this).getCodeBase(), url);
  351.          }
  352.       } catch (MalformedURLException e) {
  353.          System.out.println(e);
  354.          return null;
  355.       }
  356.    }
  357.  
  358.    public void mouseClicked(MouseEvent e) {
  359.    }
  360.  
  361.    public void mouseEntered(MouseEvent e) {
  362.       if (this.enterBackColor != null) {
  363.          ((Component)this).setBackground(this.enterBackColor);
  364.          ((Component)this).repaint();
  365.       }
  366.  
  367.       if (this.enterTextColor != null) {
  368.          if (this.field_0 != null) {
  369.             this.field_0.setColor(this.enterTextColor);
  370.          }
  371.  
  372.          ((Component)this).repaint();
  373.       }
  374.  
  375.       if (this.statusBarText != null) {
  376.          ((Applet)this).showStatus(this.statusBarText);
  377.       }
  378.  
  379.       if (this.enterSound != null) {
  380.          this.enterSound.play();
  381.       }
  382.  
  383.       if (this.link != null) {
  384.          ((Component)this).setCursor(new Cursor(12));
  385.       }
  386.  
  387.    }
  388.  
  389.    public void mouseExited(MouseEvent e) {
  390.       if (this.enterBackColor != null) {
  391.          ((Component)this).setBackground(this.backColor);
  392.          ((Component)this).repaint();
  393.       }
  394.  
  395.       if (this.enterTextColor != null) {
  396.          this.field_0.setColor(this.textColor);
  397.          ((Component)this).repaint();
  398.       }
  399.  
  400.       if (this.link != null) {
  401.          ((Component)this).setCursor(new Cursor(0));
  402.       }
  403.  
  404.    }
  405.  
  406.    public void mousePressed(MouseEvent e) {
  407.       if (this.clicSound != null) {
  408.          this.clicSound.play();
  409.       }
  410.  
  411.       if (this.link != null) {
  412.          String target = ((Applet)this).getParameter("target");
  413.          if (target == null) {
  414.             target = "_blank";
  415.          }
  416.  
  417.          URL u = this.giveURL(this.link);
  418.          ((Applet)this).getAppletContext().showDocument(u, target);
  419.       }
  420.  
  421.    }
  422.  
  423.    public void mouseReleased(MouseEvent e) {
  424.    }
  425. }
  426.